package top.resty.erp.util;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <pre>
 *
 * </pre>
 *
 * @author : resty
 * @date : 2021年03月23 13:10
 */
public class ErpUtils {
	/**
	 * 获取以当前时间转换的产品编号ID
	 * @return
	 */
	public static String getWareHouseId(){
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmms");
		return format.format(new Date());
	}
	
	public static void exportExcel(List<?> list) throws IllegalAccessException {
		
		//创建一个Excel文件
		HSSFWorkbook workbook = new HSSFWorkbook();
		//创建一张工作表
		HSSFSheet sheet = workbook.createSheet("sheet1");
		
		for (int i = 0; i < list.size(); i++) {
			
			Object o = list.get(i);
			Field[] declaredFields = o.getClass().getDeclaredFields();
			for (int j = 0; j < declaredFields.length; j++) {
				Field declaredField = declaredFields[j];
				declaredField.setAccessible(true);
				System.out.println(declaredField.getType()==Integer.class);
				if (Integer.class.equals(declaredField.getType())) {
					int anInt = declaredField.getInt(declaredField);
					System.out.println(anInt);
				} else if (String.class.equals(declaredField.getType())) {
					Object o1 = declaredField.get(declaredField);
					System.out.println(o1);
				}
			}
			
		}
		
		
		
		
	}
}
